using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BaseForum.Mockup;
using BaseForum.Model;
using System.Collections;
using BaseForum.Dao;

namespace WebForum.App_Data
{
    public class ForumDataSource
    {
        private static readonly ForumDao forumDao = new ForumDao();
        /// <summary>
        /// get forum by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Forum Get(int id)
        {
            //foreach (Forum f in WebForumMockup.forums)
            //{
            //    if (f.Id == id)
            //        return f;
            //}
            //return null;
            return forumDao.Get(id);
        }
        /// <summary>
        /// Get all parent forum
        /// Return forum if have sub forum
        /// </summary>
        /// <returns></returns>
        public static List<Forum> List()
        {
            //List<Forum> forums = WebForumMockup.forums;
            //return forums;
            return forumDao.List();
        }
        /// <summary>
        /// Get all sub forum by parent forum id
        /// </summary>
        /// <param name="pID"></param>
        /// <returns></returns>
        public static ArrayList List(int? pID)
        {
            //ArrayList list = new ArrayList();
            ////List<Forum> cForum = new List<Forum>();
            //foreach (Forum f in WebForumMockup.forums)
            //{
            //    if (f.ParrentForum != null && f.ParrentForum.Id == pID)
            //    {
            //        list.Add(f);
            //    }
            //}
            //return list;
            ArrayList list = new ArrayList();
            foreach (Forum f in forumDao.List(pID))
            {
                list.Add(f);
            }
            return list;
        }
        /// <summary>
        /// Get sub forum, with number
        /// </summary>
        /// <param name="pID"></param>
        /// <param name="num"></param>
        /// <returns></returns>
        public static ArrayList List(int pID, int num)
        {
            ArrayList list = new ArrayList();
            foreach (Forum f in List(pID))
            {
                list.Add(f);
                if (list.Count == num) break;
            }
            return list;
        }
        /// <summary>
        /// Insert forum
        /// </summary>
        /// <param name="forum"></param>
        /// <returns></returns>
        public static bool Insert(Forum forum)
        {
            return forumDao.Insert(forum);
        }
        /// <summary>
        /// Delete User
        /// </summary>
        /// <param name="fID"></param>
        /// <returns></returns>
        public static bool Delete(Int32 Id)
        {
            return forumDao.Delete(Id);
        } 
        public static bool Update(Forum forum)
        {
            return forumDao.Update(forum);
        }
        /// <summary>
        /// Delete for Object DataSource
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public static bool UpdateNull(int Id)
        {
            //return forumDao.Update(forum);
            return true;
        }
    }
}
